'''
@Author ：czh
@Date ：2022/3/8 0008 16:40 
@remark：
'''
import json

from utils.LogHandler import logger


class AssertUtil:


    #判断状态码是否相对
    def assert_code(self,code,expected_code):
        try:
            assert  int(code) == int(expected_code)
            return True
        except:
            # self.log.error("{}{}状态码错误".format(code,expected_code))
            raise

    #判断body是否相等
    def assert_body(self,body,expected_body):
        try:
            assert  body == expected_body
            return True
        except:
            # self.log.error("{}{}内容不相等".format(body,expected_body))
            raise

    #判断返回结果是否包含期望结果
    def assert_in_body(self,body,expected_body):
        try:
            for key in expected_body:
                if (key in body) and (expected_body[key]==body[key]):
                    return True
                else:
                    return False
        except:
            logger().error("不包含错误{}{}".format(body,expected_body))



if __name__ == '__main__':
    l = {
 "success": True
}
    l2 = {'success': True, 'data': {'authentication': {'id': '200417', 'userName': '生活用纸年会管理员', 'mobilePhone': '200417',
                                                       'email': 'admin@cnhpia.org', 'key': '200417admin@cnhpia.org'},
                                    'exhibition': {'id': '210417', 'name': '2021南京生活用纸年会', 'namespace': '21/0417',
                                                   'openDate': '2021-05-26 00:00:00',
                                                   'closeDate': '2021-05-28 23:59:59', 'openStatus': 'OPEN',
                                                   'accessInterval': '0', 'appid': 'wx5de753c98e0c75c4',
                                                   'smsSign': '生活用纸年会', 'ocrEnable': 'Yes',
                                                   'wechatConfig': '{  "scenarioMap": {},    "openLocationMap": {       "latitude": 31.99214,       "longitude": 118.7155,        "name": "南京国际博览中心",        "address": "南京市建邺区江东中路300号",        "scale": 5,        "infoUrl": ""    },    "shareConfig": {        "title": "诚邀您参加FOCUS生活用纸和卫生用品国际论坛",        "desc": "2021.4.24-25南京。对“焦”生活用纸和卫生用品两大行业，集“聚”全球业内专家",        "link": "/share.html?appid=wx5de753c98e0c75c4&source=120",        "imgUrl": "https://asset.zzxes.com.cn/cus/20/0417/seminar/seminar_logo_square.png"    },    "shareConfigIndex":{             "title": "生活用纸和卫生用品云服务",            "desc": "拥有直播、行业新闻播报、云培训、线上论坛、云展会、供需平台、云洽谈等多种功能。欢迎登录！",            "link": "/cloudShare.html?path=home",            "imgUrl":"https://asset.zzxes.com.cn/share/IMG_6167.JPG"        },"shareConfigAudio":{              "title": "生活用纸和卫生用品行业新闻周报",            "desc": "每周四早8:30，生活用纸和卫生用品行业播报，每周行业热点新闻，读给您听！",            "link": "/cloudShare.html?path=audioList&audioId=15116",            "imgUrl":"https://asset.zzxes.com.cn/share/%E9%9F%B3%E9%A2%91%E5%88%97%E8%A1%A8-%E5%88%86%E4%BA%AB%E5%9B%BE.jpg"        },"shareConfigActivity":{          "title":"",          "desc":"",          "link":"",          "imgUrl":""      }}',
                                                   'registerConfig': '{"scenarioMap":{}}',
                                                   'exhibitorAppId': 'wx5de753c98e0c75c4',
                                                   'createTime': '2021-09-09 18:37:40'}}, 'errorCode': '0',
          'elapse': '0'}

    a=AssertUtil().assert_in_body(l2,l)
    print(a)